#include "cueilleur_de_touches.h"
#include "interface/interface.h"


void cueilleur_de_touches::touche_pressee(int t, int ct, bool relache) {
	if(ct == module_interface::touche_shift_gauche) {
		pedale_douce_ = !relache;
		return;
	}
	
	if(relache)
		return;
	
	char touche = static_cast<char>(t);
	if(touche >= 'A' && touche <= 'Z') touche -= ('A' - 'a');
	touche_du_piano note = pas_de_touche;
	
	switch(touche) {
		case 'a': if(qwerty_) note = do3; break;
		case 'q': if(!qwerty_) note = do3; break;
		case 'w': if(qwerty_) note = do_diese3; else modificateur_touche_ = -2; break;
		case 'z': if(!qwerty_) note = do_diese3; else modificateur_touche_ = -2; break;
		case 's': note = re3; break;
		case 'e': note = re_diese3; break;
		case 'd': note = mi3; break;
		case 'f': note = fa3; break;
		case 't': note = fa_diese3; break;
		case 'g': note = sol3; break;
		case 'y': note = sol_diese3; break;
		case 'h': note = la3; break;
		case 'u': note = la_diese3; break;
		case 'j': note = si3; break;
		case 'k': note = do4; break;
		case 'o': note = do_diese4; break;
		case 'l': note = re4; break;
		case 'p': note = re_diese4; break;
		case ';': if(qwerty_) note = mi4; break;
		case 'm': if(!qwerty_) note = mi4; break;
		case 'x': modificateur_touche_ = -1; break;
		case 'c': modificateur_touche_ = 0; break;
		case 'v': modificateur_touche_ = 1; break;
		default: break;
	}
	
	
	if(note != pas_de_touche)
		note = static_cast<touche_du_piano>(note + modificateur_touche_ * 12);
	
	if(note != pas_de_touche)
		panier_.deposer(note);
}
